*************************************************************************
************************Figure 4: IDENTIFYING SPILLOVERS*****************
*************************************************************************


grstyle init
grstyle set plain
grstyle set color tableau


cd $PATH

* trend graphs

use so2_match_wide.dta, clear

reshape long so2_total_ so2_power_ so2_manu_, i(commid) j(year)
rename so2_total_ so2_total
rename so2_power_ so2_power
rename so2_manu_ so2_manu

g so2_total_ann=so2_total*3600*24*365
g so2_manu_ann=so2_manu*3600*24*365
g so2_power_ann=so2_power*3600*24*365

* aggregated so2 emissions: by tcz and non-tcz communities
collapse (sum) so2_manu_ann so2_power_ann so2_total_ann, by(tcz year)

drop if year<1990

twoway (line so2_power_ann year if tcz==1, lw(medthick) lc(gs6)) (line so2_power_ann year if tcz==0, lw(medthick) lp(dash) lc(gs10)),  ///
 xtitle("Year", size(small)) ytitle("SO2 emissions (kg/m2/year)", size(small) margin(small)) xlabel(1990(5)2015, labsize(small))  ylabel(, labsize(small))  ///
 legend(pos(6) cols(2) label(1 "TCZ regions") label(2 "Non-TCZ regions") region(lwidth(none))) 

graph export fig4_so2_power.eps, replace
 
twoway (line so2_manu_ann year if tcz==1, lw(medthick) lc(gs6)) (line so2_manu_ann year if tcz==0, lw(medthick) lp(dash) lc(gs10)),  ///
 xtitle("Year", size(small)) ytitle("SO2 emissions (kg/m2/year)", size(small) margin(small))  ///
 xlabel(1990(5)2015, labsize(small))  ylabel(, gmin gmax labsize(small)) legend(pos(6) cols(2) label(1 "TCZ regions") label(2 "Non-TCZ regions") region(lwidth(none))) 

graph export fig4_so2_manu.eps, replace
 
 
* Residual plots

use incdistribution.dta, clear
merge 1:1 commid WAVE using so2_match_long.dta, keep(match) nogen 
merge m:1 commid using kernelmatch.dta, keep(match) nogen

g loggini=log(gini)
g logso2_manu=log(1+so2_manu_ann)
g logso2_power=log(1+so2_power_ann)
g logso2_total=log(1+so2_total_ann)

g post=WAVE>1998

global score comm denc div econ health house market soc trans edc mart sani

xtset commid WAVE

xtreg logso2_manu tcz post $score i.WAVE, fe vce(cluster commid)
predict resid_manu, residuals

xtreg logso2_power tcz post $score i.WAVE, fe vce(cluster commid)
predict resid_power, residuals

collapse (mean) resid_manu resid_power, by(tcz WAVE)

twoway (scatter resid_manu WAVE if tcz==1, mcolor(gs8)) (scatter resid_manu WAVE if tcz==0, msymbol(Oh) mcolor(gs8)), legend(label( 1 "TCZ communities") label( 2 "Non-TCZ communities" ) region(lstyle(none)) ) xlabel(1989 1991 1993 1997 2000 2004 2006 2009 2011 2015) ytitle("Average residulized emissions from manufacturing sector", size(small)) xtitle("Survey Year", margin(small))  ylabel(-0.01(0.005)0.01, gmin gmax labsize(small))

graph export fig4_resid_manu.eps, replace


twoway (scatter resid_power WAVE if tcz==1, mcolor(gs8)) (scatter resid_power WAVE if tcz==0, msymbol(Oh) mcolor(gs8)), legend(label( 1 "TCZ communities") label( 2 "Non-TCZ communities" ) region(lstyle(none))) xlabel(1989 1991 1993 1997 2000 2004 2006 2009 2011 2015) ytitle("Average residulized emissions from power sector", size(small)) xtitle("Survey Year", margin(small)) 

graph export fig4_resid_power.eps, replace



